import type { FormItemRule } from "element-plus";

/**
 * 密码规则
 */
export const passwordRule: FormItemRule = {
  message: "限定20个以内字母、数字",
  pattern: /^[0-9a-zA-Z]{0,20}$/,
  trigger: "blur",
};

export const getConfirmPasswordRule = (
  getPassword: () => string,
): FormItemRule => {
  return {
    validator: (_rule, value, callback) => {
      if (value !== getPassword()) {
        callback("两次输入密码不一致!");
      } else {
        callback();
      }
    },
    trigger: "blur",
  };
};
